import useRequet, { RespData } from "../hook/network"
import { ElMessage } from 'element-plus'
import { Option } from '../types/index'

import { ref } from 'vue'

const request = useRequet({ path: "" });

type LastOrder = {
  details: {},
  originalPriceShow: string,
  orderDetailSumMoneyShow: string,
}
export const getLastOrderAdd = (id: number | string) => {
  let list = ref<any[]>([])

  return new Promise<LastOrder[]>((resolve, reject) => {
    request.sendRequest({
      address: `pay/order/getCustomerLastAddOrder/${id}`,
      params: {},
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取最新订单' || resp.msg)
        list.value = resp.data
        resolve(list.value)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error('获取最新订单' || resp.msg)
        reject(ElMessage.error(resp.msg))
      },
      method: "GET",
    })
  })
}